package com.ca.ridersclubapplication.view.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.ca.ridersclubapplication.R;
import com.ca.ridersclubapplication.util.ImageUtils;

public class ImageFragment extends Fragment {

    private final Activity activity;
    private final String imageUrl;

    private ImageView imageView;

    public ImageFragment(Activity activity, String imageUrl) {
        this.activity = activity;
        this.imageUrl = imageUrl;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_image_layout, container, false);

        initView(view);

        imageView.setOnClickListener(v -> activity.finishAfterTransition());

        return view;
    }

    private void initView(View view) {
        imageView = view.findViewById(R.id.iv);
        ImageUtils.loadImage(getContext(), imageUrl, imageView);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
